package com.service.admin;

import com.dao.admin.AdminLoginDao;
import com.po.Admininfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestParam;

import javax.jms.Session;
import javax.servlet.http.HttpSession;
@Service("adminService")
@Transactional
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminLoginDao adminDao;

    @Override
    public String login(Admininfo admininfo, Model model, HttpSession session) {
        System.out.println("======"+admininfo.getA_name());
        System.out.println("======"+admininfo.getA_password());
        if(adminDao.login(admininfo) != null && adminDao.login(admininfo).size() > 0) {
            //验证了用户名不为空且返回的list集合长度不为空。
            session.setAttribute("admin", admininfo.getA_name());
            //添加商品与修改商品页面使用
            return "admin/main";
        }
        model.addAttribute("msg", "用户名或密码错误！");//传递数据给view
        //暴露为模型数据
        return "admin/login";
    }

//    @Override
//    public String login(Model model,String a_name,String a_password) {
//        System.out.println("======"+a_name);
//        System.out.println("======"+a_password);
//        if(a_name.equals(adminDao.login(admin)) && a_password.equals("123")) {
//            //验证了用户名不为空且返回的list集合长度不为空。
//            //session.setAttribute("admin", admin);
//            //添加商品与修改商品页面使用
//                return "admin/main";
//        }
//        model.addAttribute("msg", "用户名或密码错误！");//传递数据给view
//        //暴露为模型数据
//        return "admin/login";
//    }

    }

